const data = [
  {
    name: "小明",
    age: 16,
  },
  {
    name: "小明",
    age: 14,
  },
  {
    name: "小李",
    age: 23,
  },
  {
    name: "小红",
    age: 18,
  },
  {
    name: "小红",
    age: 21,
  },
];
//根据名称只筛选出第一次出现的数据
const result = data.reduce((acc, current) => {
  if (!acc[current.name]) {
    acc[current.name] = current;
  }
  return acc;
}, {});

const finalResult = Object.values(result);
console.log(finalResult);

/**
 * [
  { name: '小明', age: 16 },
  { name: '小李', age: 23 },
  { name: '小红', age: 18 }
]
 */
